Skip to content

Conversation

@adwinwhite
Copy link
Contributor

Fixes rust-lang/trait-system-refactor-initiative#166.

Duplicated the normalize_param_env_or_error function to force deep normalization for compare_impl_item.

r? @lcnr

@rustbot
Copy link
Collaborator

rustbot commented Nov 26, 2025

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Nov 26, 2025
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for working on this!

View changes since this review

// An unnormalized env is better than nothing.
debug!("normalize_param_env_or_error: errored resolving outlives predicates");
return elaborated_env;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need to split outlives vs non-outlives predicate norm in the new solver. This only matters for the old one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that way you also don't need a separate do_deeply_normalize_predicates function as you only call it once

Comment on lines +349 to +351
drop(infcx.take_registered_region_obligations());
drop(infcx.take_registered_region_assumptions());
drop(infcx.take_and_reset_region_constraints());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, this feels... really bad xd

like, that's kind of the point of what we're doing here, but still

Does not dropping these things and instead not emitting a span_delayed_bug if there are errors also work? And also add an explicit comment referencing the FIXME from the function docs


debug!("normalize_param_env_or_error: elaborated-predicates={:?}", predicates);

let elaborated_env = ty::ParamEnv::new(tcx.mk_clauses(&predicates));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think we have to create a new param_env at all here 🤔 unsure why we do it in the old solver...

wanna update the new solver to just use the unnormalized_env instead?

// FIXME(-Zhigher-ranked-assumptions): this is a hack to walk around the fact that we don't support
// placeholder assumptions right now.
// We should remove this once we have proper support for implied bounds on binders.
/// Deeply normalize the param env using the next solver.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Deeply normalize the param env using the next solver.
/// Deeply normalize the param env using the next solver ignoring
/// region errors.
///
/// FIXME(-Zhigher-ranked-assumptions): this is a hack to work around
/// the fact that we don't support placeholder assumptions right now
/// and is necessary for `compare_method_predicate_entailment`, see the
/// use of this function for more info. We should remove this once we
/// have proper support for implied bounds on binders.

elaborated a bit and also want the FIXME to be part of the doc comment. The fact that this function is somewhat scuffed and shouldn't be used should be visible in the docs

Comment on lines +201 to +202
// FIXME: Temporary placeholders may get added to infcx's region constraints/obligations,
// which can cause problem for `resolve_regions`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean here? I agree that we may get constraints involving placeholders from this, but that's fine™

We have the same behavior when relating binders and what not. The way we handle such placeholder constraints may change going forward and ideally we'd eagerly handle all of them when "exiting" the binder again, but for now "leaking" these constraints is normal

// We should remove this once we have proper support for implied bounds on binders.
/// Deeply normalize the param env using the next solver.
#[instrument(level = "debug", skip(tcx))]
pub fn deeply_normalize_param_env_or_error<'tcx>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn deeply_normalize_param_env_or_error<'tcx>(
pub fn deeply_normalize_param_env_ignoring_regions<'tcx>(

let param_env = traits::normalize_param_env_or_error(tcx, param_env, normalize_cause);
// FIXME(-Zhigher-ranked-assumptions): lazy normalization may postpone region constraints to
// an infcx that checks regions. Deeply normalize the param env in the next solver as well.
// cc trait-system-refactor-initiative/issues/166.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// cc trait-system-refactor-initiative/issues/166.
// FIXME(-Zhigher-ranked-assumptions): The `hybrid_preds`
// should be well-formed. However, using them may result in
// region errors as we currently don't track placeholder
// assumptions.
//
// To avoid being backwards incompatible with the old solver,
// we also eagerly normalize the where-bounds in the new solver
// here while ignoring region constraints. This means we can then
// use where-bounds whose normalization results in placeholder
// errors further down without getting any errors.
//
// It should be sound to do so as the only region errors here
// should be due to missing implied bounds.
//
// cc trait-system-refactor-initiative/issues/166.

elaborated a bit here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

old solver doesn't check normalization constraints in compare_impl_item

4 participants